<template>
  <div class="my-container">
    <!-- 顶部 -->
    <div class="top-container">
      <div class="top">
        <div class="top-left">
          <!-- 用户昵称和简介 -->
          <h2 class="title">{{ userInfo.nickname }}</h2>
          <p class="sub-title">{{ userInfo.intro }}</p>
        </div>
        <div class="top-right">
          <!-- 用户头像 -->
          <img @click="touserinfo" :src="avatarUrl" alt="" />
        </div>
      </div>
      <div class="bottom">
        <!-- 答题情况 -->
        <ul>
          <li>
            <span class="num">998</span>
            <span class="sub">累计答题</span>
          </li>
          <li>
            <span class="num">998</span>
            <span class="sub">收藏题目</span>
          </li>
          <li>
            <span class="num">998</span>
            <span class="sub">我的错题</span>
          </li>
          <li>
            <span class="num">998<i>%</i></span>
            <span class="sub">正确率</span>
          </li>
        </ul>
      </div>
    </div>
    <!-- 底部 -->
    <div class="bottom-container">
      <!-- 职位单元格 -->
      <!-- class 是给这个组件单独加的样式 -->
      <MMCell
        class="position-cell circle"
        :value="userInfo.position"
        icon="iconicon_mine_gangwei"
        title="我的岗位"
        @click="toEdit"
      ></MMCell>
      <!-- 面经数据 -->
      <div class="data-container">
        <h2>面经数据</h2>
        <ul>
          <li>
            <div class="top">昨日阅读<span>+300</span></div>
            <div class="mid">17</div>
            <div class="bottom">阅读总数</div>
          </li>
          <li>
            <div class="top">昨日阅读<span>+300</span></div>
            <div class="mid">17</div>
            <div class="bottom">阅读总数</div>
          </li>
          <li>
            <div class="top">昨日阅读<span>+300</span></div>
            <div class="mid">17</div>
            <div class="bottom">阅读总数</div>
          </li>
        </ul>
      </div>
      <!-- cell的容器 -->
      <div class="cell-container">
        <MMCell
          value="1"
          icon="iconicon_mine_mianjing"
          title="我的面经分享"
        ></MMCell>
        <MMCell
          value="1"
          icon="iconicon_mine_xiaoxi"
          @click="tomessage"
          title="我的消息"
        >
        </MMCell>
        <MMCell
          value="2"
          icon="iconicon_mine_tikushoucang"
          title="收藏的题库"
        ></MMCell>
        <MMCell
          value="3"
          icon="iconicon_mine_qiyeshoucang"
          title="收藏的企业"
        ></MMCell>
        <MMCell value="4" icon="iconicon_mine_cuoti" title="我的错题"></MMCell>
        <MMCell
          value="5"
          icon="iconbtn_shoucang_sel"
          title="收藏的面试经验"
        ></MMCell>
      </div>
    </div>
  </div>
</template>

<script>
import MMCell from '@/components/MMCell'
// 导入辅助函数,因为需要用到这些,使用state中的数据,导入mapstate
// 使用getters中的数据,那就导入mapGetters
import { mapState, mapGetters } from 'vuex'
export default {
  name: 'my',
  //  注册
  components: {
    MMCell
  },
  // 计算属性
  computed: {
    // 个性的签名,昵称,职位这些都在userinfo之中
    ...mapState(['userInfo']),
    // 头像
    ...mapGetters(['avatarUrl'])
  },
  methods: {
    touserinfo () {
      this.$router.replace('./userinfo')
    },
    tomessage () {
      this.$router.replace('./message')
    },
    // 点击编辑岗位
    toEdit () {
      // 点击的时候会他跳转到editInfo页面,但同时,也会在url中把这些东西
      // 携带过去就是问号后面这些个东西prop=position&redirect=my
      this.$router.replace('/editInfo?prop=position&redirect=my')
    }
  }
}
</script>

<style lang="less">
.my-container {
  .top-container {
    background-color: @main-color;
    padding-top: 31px;

    padding-bottom: 55px;
    .top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-left: 15px;
      padding-right: 37px;
      .top-left {
        .title {
          font-size: 21px;
          color: @white-color;
        }
        .sub-title {
          margin-top: 6px;
          opacity: 0.7;
          font-size: 12px;
          color: @white-color;
        }
      }
      .top-right {
        img {
          border-radius: 50%;
          width: 50px;
          height: 50px;
          border: 3px solid @subdominant-font-color;
        }
      }
    }
    .bottom {
      padding-left: 15px;
      padding-right: 15px;

      ul {
        display: flex;
        justify-content: space-between;
        margin-top: 31px;
        li {
          span {
            color: @white-color;
            display: block;
            text-align: center;
            &.num {
              font-size: 21px;
            }
            &.sub {
              margin-top: 6px;
              font-size: 12px;
              opacity: 0.7;
            }
            i {
              font-size: 12px;
            }
          }
        }
      }
    }
  }
}
.bottom-container {
  // background-color: @bg-color;
  padding: 15px;
  position: relative;
  &.circle {
    border-radius: 8px;
  }
  //用来定位第一个组件
  .position-cell {
    position: absolute;
    top: -39px;
  }
  .mm-cell {
    // 如何提升优先级?可以把它放在父级里面,前面加一个父级类名,提高他的权重
    height: 55px;
    width: 345px;
    .iconfont {
      margin-right: 12px;
    }
  }
}

.mm-cell .iconfont {
  margin-right: 12px;
}

// 面经样式
.data-container {
  background-color: @white-color;
  padding-top: 19px;
  padding-left: 15px;
  padding-bottom: 16px;
  margin-top: 11px;
  h2 {
    font-size: 21px;
    margin-top: 0;
  }
  ul {
    display: flex;
    justify-content: space-around;
    li {
      text-align: center;
      .top {
        color: @subdominant-font-color;
        font-size: 10px;
        span {
          color: @assist-color;
        }
      }
      .mid {
        font-weight: 900;
        font-size: 21px;
        margin-top: 10px;
      }
      .bottom {
        font-size: 12px;
        margin-top: 6px;
      }
    }
  }
}

// 底部的样式
.cell-container {
  border-radius: 8px;
  margin-top: 10px;
  overflow: hidden;
}
</style>
